<?php
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * date: 2021-09-09 21:04:35
 * @LastEditors: Sam
 * @LastEditTime: 2021-09-09 21:22:32
 */


namespace app\admin\controller;
use app\admin\model\{User as UserModel,Sign as SignModel,SignLog};

/**
 * 签到
 * @author Sam
 * date 2021-09-09
 */
class Sign extends Base
{

    /**
     * 签到列表
     * date 2020/8/15 14:09
     */
    public function sign_list() {
        $search  = request()->param();
        $where = [];
        if(!empty($_GET['nickname'])){
            $uid = UserModel::where('nickname','like',"%{$search['nickname']}%")->column('id');
            if(count($uid)) $where[] = ['id','in',$uid];
        }
        if(IS_POST) {
            $db   = SignLog::with('user')->where($where)->order('id desc');
            $list = $db->limit(paginator())->select();
            if(count($list)){
                foreach ($list as $key => $value) {
                    $value['avatar'] = table_img($value['avatar']);
                    $value['create_time'] = date('Y-m-d H:i:s',$value['avatar']);
                }
            }
            admin_response(0, 'success', $list, $db->count());
        }
        if(IS_EXCEL) {
            $db =  $db   = SignLog::with('user')->order('id desc');
            big_array_to_csv($db, '签到记录', [
                'openid'      => 'openid',
                'nickname'    => '昵称',
                'year'        => '年',
                'month'       => '月',
                'day'         => '日',
                'create_time' => '签到时间'
            ]);
        }
        return $this->render_table([
             "page"=>true,
             'export'=>true,
             "cols" => [ 
                     ["field"=>"id", "title"=>"编号","align"=>"center"],
                     ["field"=>"avatar", "title"=>"头像","align"=>"center"],
                     ["field"=>"nickname", "title"=>"昵称","align"=>"center"],
                     ["field"=>"create_time", "title"=>'签到时间',"align"=>"center"]
 
             ],
             "where"=>[
                'nickname'  => ['type'=>'input', 'title'=>'用户昵称','placeholder'=>'用户昵称搜索'],
            ]
             ],false);
    }
}